{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prepare csv input file for Instance Segmentation Mechanical Turk task"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing csv file turk_input.csv\n"
     ]
    }
   ],
   "source": [
    "import glob\n",
    "import os\n",
    "import urllib\n",
    "\n",
    "def prep_folder(path):\n",
    "    \"\"\"converts each image paths in a folder to its corresponding s3 url.\n",
    "    \"\"\"\n",
    "    fs = glob.glob(os.path.join(dataset_folder, '*.jpg'))\n",
    "    fs = [s3_prefix + urllib.request.pathname2url(f) for f in fs]\n",
    "    return fs\n",
    "\n",
    "def prep_file(path):\n",
    "    \"\"\"converts an individual file name to a s3 url\n",
    "    \"\"\"\n",
    "    f = [s3_prefix + urllib.request.pathname2url(path)]\n",
    "    return f\n",
    "\n",
    "def create_turk_csv(f):\n",
    "    \"\"\"writes a csv file with image urls corresponding to a batch of mturk jobs.\n",
    "    \n",
    "    Args:\n",
    "        f : list of image urls\n",
    "    \"\"\"\n",
    "    dat = 'turk_input.csv'\n",
    "    print(\"Writing csv file {}\".format(dat))\n",
    "    with open(dat,'w') as file:\n",
    "        file.write('image_url\\n')\n",
    "        for x in f:\n",
    "            file.write(x)\n",
    "#             print(x)\n",
    "            file.write('\\n')\n",
    "\n",
    "s3_prefix = 'https://locobot-bucket.s3-us-west-2.amazonaws.com/hk_dataset/'\n",
    "dataset_folder = '/scratch/apratik/mc_new/hk_dataset/'\n",
    "f = 'hk_2020-12-02 16:14:27.827684_locobot_capture__kwhq4ca6.jpg'\n",
    "\n",
    "create_turk_csv(prep_file(f))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "loco",
   "language": "python",
   "name": "loco"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
